﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Zhaoxi.FactoryDeviceSystem.Models;
using Zhaoxi.FactoryDeviceSystem.Utils;

namespace Zhaoxi.FactoryDeviceSystem.UControls
{
    public partial class UCDeviceControl : UserControl
    {
        public UCDeviceControl()
        {
            InitializeComponent();
        }

        //DeviceNo  DeviceName  Power  Temperature Speed  Pressure  RunState  DeviceData---设备数据对象
        //设备编号
        public int DeviceNo { get; set; }

        //设备名称
        public string DeviceName
        {
            get { return lblDevName.Text; }
            set { lblDevName.Text = value; }
        }
        //功率
        public int Power
        {
            get { return txtPower.DataValue.GetInt(); }
            set { txtPower.DataValue = value.ToString(); }
        }

        //温度
        public decimal Temperature
        {
            get { return txtTemperature.DataValue.GetDecimal(); }
            set { txtTemperature.DataValue = value.ToString("0.0"); }
        }

        //速度
        public int Speed
        {
            get { return txtSpeed.DataValue.GetInt(); }
            set { txtSpeed.DataValue = value.ToString(); }
        }

        //压力
        public decimal Pressure
        {
            get { return txtPressure.DataValue.GetDecimal(); }
            set { txtPressure.DataValue = value.ToString("0.00"); }
        }

        //设备状态
        public bool RunState
        {
            get { return swState.Checked; }
            set { swState.Checked = value; }
        }

        private DeviceData deviceInfo;
        //设备数据信息
        public DeviceData DeviceInfo
        {
            get { 
               deviceInfo = new DeviceData();
                deviceInfo.Power = Power;
                deviceInfo.Temperature = Temperature;
                deviceInfo.Speed = Speed;   
                deviceInfo.Pressure = Pressure;
                return deviceInfo;
            }
            set {
                deviceInfo= value;
                Power = deviceInfo.Power;
                Temperature=deviceInfo.Temperature;
                Speed=deviceInfo.Speed;
                Pressure=deviceInfo.Pressure;
            }
        }

        //清空设备数据
        public void ClearData()
        {
            DeviceInfo = new DeviceData()
            {
                Power=0,
                Temperature=0.0m,
                Speed=0,
                Pressure=0.00m
            };
        }

        //设备信息加载
        public void LoadData(DeviceData data,bool state)
        {
            DeviceInfo = data;
            RunState = state;
        }

        //设备初始设置
        public void InitDevice(int devNo,string devName)
        {
            DeviceNo= devNo;
            DeviceName= devName;
            ClearData();
            RunState = false;
        }

    }
}
